package cn.stylefeng.guns.modular.task.service.impl;

import java.io.Serializable;
import java.util.List;

import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import cn.stylefeng.guns.base.pojo.page.LayuiPageFactory;
import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.modular.task.entity.TaskDetailed;
import cn.stylefeng.guns.modular.task.mapper.TaskDetailedMapper;
import cn.stylefeng.guns.modular.task.model.params.TaskDetailedParam;
import cn.stylefeng.guns.modular.task.model.result.TaskDetailedResult;
import cn.stylefeng.guns.modular.task.model.result.grRtaskSummaryList;
import  cn.stylefeng.guns.modular.task.service.TaskDetailedService;
import cn.stylefeng.roses.core.util.ToolUtil;

/**
 * 作业明细表 服务实现类
 */
@Service
public class TaskDetailedServiceImpl extends ServiceImpl<TaskDetailedMapper, TaskDetailed> implements TaskDetailedService {

    @Override
    public void add(TaskDetailedParam param){
        TaskDetailed entity = getEntity(param);
        this.save(entity);
    }

    @Override
    public void delete(TaskDetailedParam param){
        this.removeById(getKey(param));
    }

    @Override
    public void update(TaskDetailedParam param){
        TaskDetailed oldEntity = getOldEntity(param);
        TaskDetailed newEntity = getEntity(param);
        ToolUtil.copyProperties(newEntity, oldEntity);
        this.updateById(newEntity);
    }

    @Override
    public TaskDetailedResult findBySpec(TaskDetailedParam param){
        return this.baseMapper.findBySpec(param);
    }

    @Override
    public List<TaskDetailedResult> findListBySpec(TaskDetailedParam param){
        return this.baseMapper.findListBySpec(param);
    }

    @Override
    public List<TaskDetailedResult> findSumListBySpec(TaskDetailedParam param){
        return this.baseMapper.findSumListBySpec(param);
    }

    @Override
    public LayuiPageInfo findPageBySpecApplets(TaskDetailedParam param,String condition){
        Page pageContext = getPageContext();
        IPage page = this.baseMapper.findPageBySpecApplets(pageContext, param,condition);
        return LayuiPageFactory.createPageInfo(page);
    }

    @Override
    public LayuiPageInfo findPageBySpec(TaskDetailedParam param,String condition){
        Page pageContext = getPageContext();
        IPage page = this.baseMapper.customPageList(pageContext, param,condition);
        return LayuiPageFactory.createPageInfo(page);
    }

    @Override
    public LayuiPageInfo findSumPageBySpec(TaskDetailedParam param,String condition){
        Page pageContext = getPageContext();
        IPage page = this.baseMapper.findSumPageBySpec(pageContext, param,condition);
        return LayuiPageFactory.createPageInfo(page);
    }

    @Override
    public LayuiPageInfo findworkerReportListPageBySpec(TaskDetailedParam param,String condition,Long operateId,Long outCustomerId,String taskWork,String v8,String carModel,Long operateId2){
        Page pageContext = getPageContext();
        IPage page = this.baseMapper.findworkerReportListPageBySpec(pageContext, param,condition, operateId,outCustomerId, taskWork,v8, carModel, operateId2);
        return LayuiPageFactory.createPageInfo(page);
    }

    @Override
    public LayuiPageInfo findworkerReportListJxPageBySpec(TaskDetailedParam param,String condition,Long operateId,Long outCustomerId,String taskWork,String v8,String carModel,Long operateId2){
        Page pageContext = getPageContext();
        IPage page = this.baseMapper.findworkerReportListJxPageBySpec(pageContext, param,condition, operateId,outCustomerId, taskWork,v8, carModel, operateId2);
        return LayuiPageFactory.createPageInfo(page);
    }

    private Serializable getKey(TaskDetailedParam param){
        return param.getId();
    }

    private Page getPageContext() {
        return LayuiPageFactory.defaultPage();
    }

    private TaskDetailed getOldEntity(TaskDetailedParam param) {
        return this.getById(getKey(param));
    }

    private TaskDetailed getEntity(TaskDetailedParam param) {
        TaskDetailed entity = new TaskDetailed();
        ToolUtil.copyProperties(param, entity);
        return entity;
    }

	@Override
	public List<grRtaskSummaryList> grRtaskSummaryList(TaskDetailedParam param, String condition,
			Long operateId, Long outCustomerId, String taskWork,String v8, String carModel,Long operateId2) {
		return this.baseMapper.grRtaskSummaryList(param,condition, operateId,outCustomerId, taskWork,v8, carModel, operateId2);
	}

	@Override
	public List<cn.stylefeng.guns.modular.task.model.result.grRtaskSummaryList> grRtaskSumList(TaskDetailedParam param,
			String condition, Long operateId, Long outCustomerId, String taskWork, String v8, String carModel,Long operateId2) {
		return this.baseMapper.grRtaskSumList(param,condition, operateId,outCustomerId, taskWork,v8, carModel, operateId2);
	}

	@Override
	public List<TaskDetailedResult> findSumtaskRankingBySpec(TaskDetailedParam param) {
		return this.baseMapper.findSumtaskRankingBySpec(param);
	}

	@Override
	public List<TaskDetailedResult> findSumtaskRankingBySpec2(TaskDetailedParam param) {
		return this.baseMapper.findSumtaskRankingBySpec2(param);
	}

	@Override
	public boolean checkmetaskRanking(TaskDetailedParam param) {
		TaskDetailedResult taskDetailedResult = this.baseMapper.checkmetaskRanking(param);
		if (taskDetailedResult == null) {
			return false;
		} else {
			return true;
		}
	}

	@Override
	public TaskDetailedResult findBySpecZuoYeZhong(TaskDetailedParam param) {
		return this.baseMapper.findBySpecZuoYeZhong(param);
	}

	@Override
	public List<TaskDetailedResult> sumGongrenMonth(TaskDetailedParam param) {
		return this.baseMapper.sumGongrenMonth(param);
	}

	@Override
	public TaskDetailedResult sumPeoples(TaskDetailedParam param, Integer operateId) {
		return this.baseMapper.sumPeoples(param,operateId);
	}

	@Override
	public List<TaskDetailedResult> findlimit9task(TaskDetailedParam taskDetailedParam) {
		return this.baseMapper.findlimit9task(taskDetailedParam);
	}

}
